﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Hime.Redist.Parsers;

namespace xowl.gmi.compiler
{
    class ViewResource : Resource
    {
        private view.ViewDefinition definition;

        public view.ViewDefinition Definition { get { return definition; } }

        public ViewResource(string file) : base(file) { }

        public override bool Load()
        {
            Program.Logger.Info("Loading " + file);
            parsers.GMIViewLexer lexer = new parsers.GMIViewLexer(new System.IO.StreamReader(file));
            parsers.GMIViewParser parser = new parsers.GMIViewParser(lexer);
            SyntaxTreeNode root = null;
            root = parser.Analyse();
            foreach (ParserError error in parser.Errors)
                Program.Logger.Error(error.Message);
            if (parser.Errors.Count != 0)
                return false;
            this.definition = new view.ViewDefinition(root);
            return true;
        }
    }
}
